package com.test.activiti;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;

import java.io.InputStream;
import java.util.zip.ZipInputStream;

/**
 * @ClasName ActivitiDeployment
 * @Descripution TODO 流程定义的部署
 * @Author leikw
 * @Date 2021/9/1 14:35
 * @Version V1.0
 */
public class ActivitiDeployment {

    /**
     * 流程定义的部署影响activiti表有哪些？
     * act_re_deployment 部署信息
     * act_re_procdef 流程定义的一些信息
     * act_ge_bytearray 流程定义的bpmn文件及png文件
     */
    public static void main(String[] args) {
        //1.创建ProcessEngine对象
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        //2.得到RepositoryService实例
        RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();

        //3.进行部署
        Deployment deployment = repositoryService.createDeployment()
                //加入bpmn与对应图片文件
                .addClasspathResource("bpmn/examine.bpmn").addClasspathResource("bpmn/examine.png")
                //设置流程名
                .name("体检流程_包含网关")
                .deploy();

        //4.检查部署的一些信息
        System.out.println(deployment.getName());  // 请假申请流程
        System.out.println(deployment.getId()); //1
        System.out.println(deployment.getDeploymentTime());  //Wed Sep 01 14:44:36 CST 2021

    }
//    public static void main(String[] args) {
//        //1.创建ProcessEngine对象
//        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
//        //2.得到RepositoryService实例
//        RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();
//
//        //3.转化出zipInputStream流对象
//        InputStream resourceAsStream =
//                ActivitiDeployment.class
//                        .getClassLoader().getResourceAsStream("bpmn/holiday.zip");
//
//        ZipInputStream zipInputStream = new ZipInputStream(resourceAsStream);
//
//        //4.进行部署
//        Deployment deployment = repositoryService.createDeployment()
//                //设置zipInputStream
//                .addZipInputStream(zipInputStream)
//                //设置流程名
//                .name("请假申请流程")
//                .deploy();
//
//
//        //4.检查部署的一些信息
//        System.out.println(deployment.getName());
//        System.out.println(deployment.getId());
//        System.out.println(deployment.getDeploymentTime());
//    }

}
